package com.lu.statistics.controller;

import com.lu.statistics.common.config.ServerResponse;
import com.lu.statistics.entity.SysAppFile;
import com.lu.statistics.entity.front.response.AppFileResponse;
import com.lu.statistics.entity.front.response.AppResponse;
import com.lu.statistics.service.SysAppFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Api(value = "APP模块", tags = {"APP文件模块"})
@RestController
@RequestMapping(value = "/api/appFile")
public class AppController {
    @Autowired
    private SysAppFileService fileService;
    @ApiOperation(value = "应用信息", notes = "APP列表")
    @GetMapping(value = "/queryAppInfo")
    public ServerResponse<List<AppFileResponse>> queryAppInfo() {
        List<AppFileResponse> newList = new ArrayList<>();
        List<SysAppFile> carouseList = fileService.queryAppFileList("CAROUSE");
        if (carouseList != null && carouseList.size() > 0) {

            for (SysAppFile carouse : carouseList) {
               String url="/api/file/previewPhoto?fileFullPath="+carouse.getImgUrl();
               carouse.setImgUrl(url);
                AppFileResponse appFileResponse = new AppFileResponse();
                BeanUtils.copyProperties(carouse, appFileResponse);
                newList.add(appFileResponse);
            }
        }
        return ServerResponse.success(newList);
    }
}
